#include <QTest>
#include <QMediaContent>
#include <QVariant>

#include "test_MediaSource.h"
#include "MediaSourceQt.h"


/** This must be a valid media path, relative to project path */
#define MEDIA_FILE_PATH    QString("sample/sample.wav")

#define MEDIA_INVALID_PATH  QString("C:/This/is/a/fake/Path.mp3")


test_MediaSource::test_MediaSource(QObject *parent) :
   QObject(parent)
{
}

/** executed before every test case */
void test_MediaSource::init()
{
   m_mediaSource = NULL;
}

/** executed after every test case */
void test_MediaSource::cleanup()
{
   if (m_mediaSource != NULL)
   {
      delete m_mediaSource;
   }
}

void test_MediaSource::testPlatformMediaContent()
{
   QString filePath = QString(PROJECT_PATH) + MEDIA_FILE_PATH;
   QMediaContent *qmedia = new QMediaContent( QUrl::fromLocalFile(filePath));

   QVERIFY( qmedia->isNull() == false);
   QCOMPARE( qmedia->canonicalUrl(), QUrl().fromLocalFile(filePath));
}

/**
 * try to create an url with invalid path.
 * QMediaContent does not fill the difference
 */
void test_MediaSource::testPlatformInvalidContent()
{
   QMediaContent *qmedia = new QMediaContent( QUrl::fromLocalFile(MEDIA_INVALID_PATH));

   QVERIFY( qmedia->isNull() == false);
   QCOMPARE( qmedia->canonicalUrl(), QUrl().fromLocalFile(MEDIA_INVALID_PATH) );
}

void test_MediaSource::testMediaContentRetrieve()
{
   QString filePath = QString(PROJECT_PATH) + MEDIA_FILE_PATH;
   QMediaContent *qmedia = new QMediaContent( QUrl::fromLocalFile(filePath));
   QString stringId("sample.wav");  /* normally computed by model */

   m_mediaSource = new MediaSourceQt( filePath, stringId, *qmedia);

   QMediaContent mediaContent = m_mediaSource->mediaContent().value<QMediaContent>();
   QCOMPARE( mediaContent.canonicalUrl(), QUrl().fromLocalFile(filePath));
}


